<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var countPairs = function (arr) {
      let mod = 1000000007
      let max = arr.reduce((a, b) => Math.max(a, b), 0) * 2
      let res = 0
      let map = new Map()
      for (let d of arr) {
        for (let i = 1; i <= max; i <<= 1) {
          let n = map.get(i - d) || 0

          res = (res + n) % mod
        }
        map.set(d, (map.get(d) || 0) + 1)
      }
      return res
    };
    console.log(countPairs([1, 3, 5, 7, 9]));
  </script>
</body>

</html>